;;; +package.el --- configuration -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

(defconst package-mirror-alist
  '((default
     ("gnu"     . "https://elpa.gnu.org/packages/")
     ("melpa"   . "https://melpa.org/packages/")
     ("org"     . "https://orgmode.org/elpa/"))
    (tuna
     ("gnu"     . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
     ("nongnu"  . "http://mirrors.tuna.tsinghua.edu.cn/elpa/nongnu/")
     ("melpa"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/"))
    (ustc
     ("gnu"     . "https://mirrors.ustc.edu.cn/elpa/gnu/")
     ("melpa"   . "https://mirrors.ustc.edu.cn/elpa/melpa/"))
    ))

(setq package-archives (assoc-default 'tuna package-mirror-alist))

;; list the wanted packages
(setq cor5corpii-package-list
      '(ace-pinyin ace-window aggressive-indent auctex cdlatex consult-yasnippet
                   corfu csv-mode diff-hl diminish embark embark-consult ess
                   ess-smart-equals expand-region flymake-popon gt
                   highlight-numbers hydra indent-bars lua-mode
                   magic-latex-buffer magit marginalia multiple-cursors
                   multi-term mwim orderless polymode poly-R posframe pyvenv
                   queue rainbow-delimiters rainbow-mode separedit sis
                   spacemacs-theme symbol-overlay undo-tree valign vertico
                   yaml-mode yasnippet-snippets))

(when (eq system-type 'windows-nt)
  (dolist (package-list-4win '(ahk-mode exec-path-from-shell))
    (push package-list-4win cor5corpii-package-list)))

;; initialize packages
(unless (bound-and-true-p package--initialized) ;; To avoid warnings in 27
  (setq package-enable-at-startup nil)          ;; To prevent initializing twice
  (package-initialize))

;; fetch the list of packages available
(unless package-archive-contents
  (package-refresh-contents))

;; install the missig packages
(dolist (package cor5corpii-package-list)
  (unless (package-installed-p package)
    (package-install package)))

;; set package-list to `package-selected-packages'
(setq package-selected-packages cor5corpii-package-list)

;; ;; -------- auto-package-update --------
;; (use-package auto-package-update
;;   :if (not (daemonp))
;;   :custom
;;   (auto-package-update-interval 7) ;; in days
;;   (auto-package-update-prompt-before-update t)
;;   (auto-package-update-delete-old-versions t)
;;   (auto-package-update-hide-results t)
;;   :config
;;   (auto-package-update-maybe))

(provide '+package)

;;; +package.el ends here
